﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SMP_QuanLySV.DAL;

namespace SMP_QuanLySV.BLL
{
    class BLLUserManager
    {
        List<User> list;
        QuanLySVDataContext db;

        // constructors
        public BLLUserManager()
        {
            db = new QuanLySVDataContext();
            this.list = db.Users.ToList();
        }

        // kiem tra 1 user co ton tai hay khong
        public bool checkValid(string username, string pass)
        {
            this.list = db.Users.ToList();
            foreach (User dt in list)
            {
                if (dt.UserID.Equals(username) && dt.Password == pass)
                    return true;
            }
            return false;
        }

        public bool updatePass(string username, string pass)
        {
            try
            {

                var temp = (from c in db.Users
                            where c.UserID == username
                            select c).First();
                User found = (User)temp;
                found.Password = pass;

                db.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
